package edu.sctu.zhengsenwen.month201506.day20150614.lock;

/**
 * Created by user15 on 2015/6/15.
 */
public class SynchronizingClass1 {

    private int contents;

    private boolean avaliable = false;


    public synchronized int get() {

        if (avaliable == false) {

            try {
                wait();
            } catch (InterruptedException e) {}

        }

        avaliable = false;

        notifyAll();

        System.out.println("取得的数据=" + contents);

        return contents;
    }


    public synchronized void put(int value) {


        if (avaliable == true) {

            try {
                wait();
            } catch (InterruptedException e) {}
            contents = value;

            System.out.println("输入的数据" + value);

            avaliable = true;

            notifyAll() ;
        }
    }


}
